package TUILayer;
import java.util.Scanner;
/**
 * Write a description of class MainMenuUI here.
 * 
 * @author Team Black 
 * @version (a version number or a date)
 */
public class MainMenuUI
{
    private PersonUI personUI;
    private OrdreUI ordreUI;
    private ProduktUI produktUI;

    public MainMenuUI()
    {
        
    }
     /**
     *  Choise Main Menu 
     */
    public void mainMenuStart()
    {
        boolean exit=false;
        while (!exit) //! means while exit not is true (that is: false)
        {
            int choise = writeMainMenu();
            if(choise == 1)
            {
                startSale();
            }
                else
                {
                    if(choise == 2){ 
                        startReturns();
                    }
                    else{
                        if(choise == 3){
                           startAddressBook();
                        }//end if
                            //else{
                            //     if(choise == 4){
                            //         startReservation();
                            //         pause();
                            // }//end if
                            if (choise == 4) 
                            {
                                writeEnd();
                                exit = true;
                            } 
                        else
                        {
                            if(!exit)
                                {
                                    System.out.print("\nForkert input, prøv igen.");
                                    pause();
                                }//end if
                            }//end else
                        }//end else
              }// end else
        }//end else
    }//end else
     /**
     *  Write Main Menu 
     */
   private int writeMainMenu()
    {       
            // creates a keyboard object to read input
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** Hovedmenu ***");
            System.out.println(" (1) Ordrehåndtering");
            System.out.println(" (2) Vare- og udlejningshåndtering");
            System.out.println(" (3) Kunde- og personalehåndtering");
            //System.out.println(" (4) Søg vare og reservere maskineri"); //Til separering af 
            //varehåndtering og udlånshåndtering ved en videreudvikling
            System.out.println(" (4) Sluk");
            System.out.print("\n Tryk for at komme videre: ");
            int choise = 0;
            try
            {
            choise = keyboard.nextInt();
                        }
            catch(Exception e)
            {
                 System.out.println("\nInput skal være et tal, prøv igen.");
                 pause();
                 mainMenuStart();
            }
          return choise;
    }
         /**
     *  Start PersonUI    
     */
    private void startAddressBook()
    {
        personUI = new PersonUI();
        personUI.startPerson();
    }
      /**
     *    Start returns
     */
    private void startReturns()
    {
        produktUI = new ProduktUI();
        produktUI.StartProdukt();
    }
     /**
     *    Start OrdreUI (sale)
     */
    private void startSale()
    {
        ordreUI = new OrdreUI();
        ordreUI.StartOrdre();
    }
    
        //     private void startReservation()
        //     {
        //        System.out.println();
        //        System.out.println("Under konstruktion");
        //     }
     /**
     *  Write End Menu 
     */
    private void writeEnd()
    {
        System.out.println(" Systemet slukker ");
    }
     /**
     *  Scanner Pause 
     */
    private void pause()
    {
        Scanner keyboard = new Scanner(System.in);
        String vent = keyboard.nextLine();
    }
}
